home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_c / pclc41.zip / TERM_IO.C < prev    next >
Text File  |  1993-09-22  |  3KB  |  114 lines

  1. /*** TERM_IO.C ***/
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "pcl4c.h"
  7. #include "term.h"
  8. #include "ascii.h"
  9. #include "dos_io.h"
  10.  
  11. /*** Display status line ***/
  12.  
  13. #define INVERSE 0x70
  14. #define RIGHTMOST 40
  15.  
  16. void DisplayLine(char *MsgPtr, char *UserPtr, int UserLength)
  17. {static int right = RIGHTMOST;
  18.  int row;
  19.  int col;
  20.  int i;
  21.  char c;
  22.  int MsgLength;
  23.  row = GetRow();
  24.  col = GetCol();
  25.  Position(24,0);
  26.  /* display message */
  27.  MsgLength = strlen(MsgPtr);
  28.  for(i=0;i<MsgLength;i++)
  29.      {AttrWrite(*MsgPtr++,INVERSE);
  30.       Position(24,(unsigned char)(i+1));
  31.      }
  32.  /* blank rest of menu bar */
  33.  for(i=MsgLength;i<right;i++)
  34.      {AttrWrite(' ',INVERSE);
  35.       Position(24,(unsigned char)(i+1));
  36.      }
  37.  right = MsgLength;
  38.  /* want response from user ? */
  39.  if(UserPtr!=NULL)
  40.      {right = RIGHTMOST;
  41.       /* input text from user */
  42.       i = 0;
  43.       while(1)
  44.           {Position(24,(unsigned char)(MsgLength+i));
  45.            c = SioKeyRead();
  46.            if((c==ESC)||(c==CAN))
  47.                {UserPtr[0] = '\0';
  48.                 break;
  49.                }
  50.            if((c=='\r')||(MsgLength+i==RIGHTMOST))
  51.                {UserPtr[i] = '\0';
  52.                 break;
  53.                }
  54.            if((c==BS)&&(i>0))
  55.                {i--;
  56.                 Position(24,(unsigned char)(MsgLength+i));
  57.                 AttrWrite(' ',INVERSE);
  58.                }
  59.            else
  60.                {/* save character & display on status line */
  61.                 UserPtr[i++] = c;
  62.                 AttrWrite(c,INVERSE);
  63.                 if(i==UserLength)
  64.                     {/* user string done */
  65.                      UserPtr[i] = '\0';
  66.                      break;
  67.                     }
  68.                }
  69.           } /* end -- while */
  70.      } /* end -- if */
  71.  Position((unsigned char)row,(unsigned char)col);
  72. }
  73.  
  74. /*** output character to serial port ***/
  75.  
  76. int PutChar(int Port, char ch)
  77. {int rc;
  78.  /* transmit character */
  79.  rc = SioPutc(Port,ch);
  80.  if(rc<0)
  81.      {printf("SioPutc Error: COM%d: ",1+Port);
  82.       SioError(rc);
  83.       SioDone(Port);
  84.       exit(1);
  85.      }
  86.  return(rc);
  87. }
  88.  
  89. /*** receive character from serial port ***/
  90.  
  91. int GetChar(int Port, int Timeout)
  92. {int rc;
  93.  rc = SioGetc(Port,Timeout);
  94.  if(rc<-1)
  95.      {printf("SioGetc Error: COM%d: ",1+Port);
  96.       SioError(rc);
  97.       exit(1);
  98.      }
  99.  return(rc);
  100. }
  101.  
  102. /*** display the error text ***/
  103.  
  104. void SayError(int Port, char *ptr)
  105. {char temp[81];
  106.  sprintf(temp,"ERROR! COM%d : %s",1+Port,ptr);
  107.  DisplayLine(temp,NULL,0);
  108.  printf("\n*** %s\n",temp);
  109.  /* cancel remote */
  110.  PutChar(Port,CAN);
  111.  PutChar(Port,CAN);
  112.  PutChar(Port,CAN);
  113. } /* end SayError */
  114.